var t = getApp();

Page({
    data: {
        language: "",
        one_url: "https://mini-app-img-1251768088.cos.ap-guangzhou.myqcloud.com/bg_1@2x.png",
        showCart: !1,
        tapOne: !1,
        setTime: null,
        countdown: "00:00:00",
        link: {},
        bonus: {},
        receive_list: [],
        receiveLast: 1,
        receivePage: 1,
        loadMore: !1
    },
    onLoad: function(a) {
        a.mid && t._setMid(option.mid);
    },
    golink: function() {
        if (!t._isTextEmpty(this.data.link.app_advert_url)) {
            if (3 != this.data.type_status.value) {
                try {
                    wx.navigateTo({
                        url: this.data.link.app_advert_url
                    });
                } catch (t) {
                    wx.reLaunch({
                        url: this.data.link.app_advert_url
                    });
                }
                return;
            }
            var a = this, e = t.getNetAddresss("plugin.red-packet.api.red-packet-logs.set-link-log");
            t._getNetWork({
                url: e,
                data: {
                    red_packet_id: a.data.amount.id
                },
                success: function(t) {
                    if (1 == t.data.result) try {
                        wx.navigateTo({
                            url: a.data.link.app_advert_url
                        });
                    } catch (t) {
                        wx.reLaunch({
                            url: a.data.link.app_advert_url
                        });
                    }
                },
                fail: function(t) {
                    setTimeout(function() {
                        a.setData({
                            tapOne: !1
                        });
                    }, 1e3), console.log(t);
                }
            });
        }
    },
    gettap: function(a) {
        var e = a.currentTarget.dataset.id;
        1 == this.data.redData.type_status.value ? 1 == this.data.redData.type_status.value && this.getHb(e) : 3 == this.data.redData.type_status.value && t.tips("请先点击顶部图片进行浏览");
    },
    receiveBonus: function() {
        var a = this, e = t.getNetAddresss("plugin.red-packet.api.red-packet-logs.receiveBonus");
        t._getNetWork({
            url: e,
            data: {
                red_packet_id: this.data.amount.id
            },
            success: function(t) {
                var e = t.data;
                0 == e.result ? wx.showToast({
                    title: e.msg,
                    icon: "none"
                }) : (a.setData({
                    linMoney: Number(e.data.amount).toFixed(2),
                    showCart: !0
                }), this.getData());
            },
            fail: function(t) {
                wx.showToast({
                    title: t,
                    icon: "none"
                }), console.log(t);
            }
        });
    },
    trggleCart: function(t) {
        this.setData({
            showCart: !1
        }), this.getData();
    },
    closeShow: function(t) {
        this.setData({
            show1: !1
        });
    },
    golingqu: function(t) {
        var a = t.currentTarget.dataset.tag;
        wx.navigateTo({
            url: "/packageC/redPacket/get_red_record/get_red_record?tag=" + a
        });
    },
    goedu: function(t) {
        wx.navigateTo({
            url: "/packageC/redPacket/red_amount/red_amount"
        });
    },
    goRank: function() {
        wx.navigateTo({
            url: "/packageC/redPacket/redRank/redRank"
        });
    },
    tapGo: function(t) {
        var a = t.currentTarget.dataset.id;
        wx.navigateTo({
            url: "/packageA/detail_v2/detail_v2?id=" + a
        });
    },
    onReady: function() {
        var t = wx.getStorageSync("langIndex");
        this.setData({
            language: t.en
        });
    },
    onShow: function() {
        this.getData(), this.getShare();
    },
    initMore: function() {
        this.setData({
            receive_list: [],
            receiveLast: 1,
            receivePage: 1,
            loadMore: !1
        });
    },
    onShareTimeline: function() {
        var t = wx.getStorageSync("yz_uid"), a = "";
        return t && (a = t), {
            title: this.data.share_title,
            query: "mid=" + a,
            imageUrl: this.data.share_pictures
        };
    },
    onShareAppMessage: function() {
        var t = wx.getStorageSync("yz_uid"), a = "";
        return t && (a = t), {
            title: this.data.share_title,
            path: "/packageC/redPacket/daily_red/daily_red?mid=" + a,
            imageUrl: this.data.share_pictures
        };
    },
    swipeToTop: function(t) {
        if (this.data.loadMore) {
            if (this.data.receiveLast <= 1) return;
            t.detail.current > this.data.receive_list.length - 2 && (this.setData({
                receivePage: this.data.receivePage + 1
            }), this.getMore());
        }
    },
    getMore: function() {
        var a = this, e = t.getNetAddresss("plugin.red-packet.api.red-packet-logs.index");
        t._postNetWork({
            url: e,
            data: {
                page: this.data.receivePage
            },
            success: function(t) {
                var e = t.data;
                1 == e.result && (a.setData({
                    receive_list: a.data.receive_list.concat(e.data.receive.receive_list.data)
                }), a.data.receiveLast <= a.data.receivePage) && (a.data.loadMore = !1);
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    getData: function() {
        var a = this;
        wx.showLoading({
            title: "加载中"
        });
        var e = this, i = t.getNetAddresss("plugin.red-packet.api.red-packet-logs.index");
        t._postNetWork({
            url: i,
            success: function(i) {
                var o = i.data;
                if (1 == o.result && (wx.hideLoading({
                    success: function(t) {}
                }), e.setData({
                    redData: o.data,
                    amount: o.data.amount,
                    receive_log: o.data.receive,
                    bjcolor: o.data.color,
                    link: o.data.link,
                    type_status: o.data.type_status,
                    syMun: (o.data.receive.amount_sum - o.data.receive.receive_amount).toFixed(2),
                    content: o.data.content,
                    goods_list: o.data.goods_list,
                    bonus: o.data.bonus,
                    receive_list: o.data.receive.receive_list.data,
                    receiveLast: o.data.receive.receive_list.last_page
                }), a.data.loadMore = !0, a.data.receiveLast <= 1 && (a.data.loadMore = !1), wx.setNavigationBarTitle({
                    title: o.data.red_packet_title
                }), e.data.syMun && e.setData({
                    bfbMum: Number(o.data.receive.receive_amount).toFixed(2) / Number(o.data.receive.amount_sum).toFixed(2) * 100
                }), 2 == e.data.type_status.value && 0 != e.data.redData.business_hours_start && !t._isTextEmpty(e.data.redData.business_hours_start) && null != e.data.redData.business_hours_start)) {
                    var s = new Date().getTime(), n = new Date(), r = n.getFullYear(), c = n.getMonth() + 1, d = n.getDate(), l = "".concat(r, "/").concat(c, "/").concat(d, " ").concat(o.data.business_hours_start, ":00");
                    l = Date.parse(l);
                    var u = Number(l) - Number(s);
                    e.setData({
                        Difference: u
                    });
                }
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    finished: function(t) {
        console.log("倒计时结束"), this.getData();
    },
    daojishi: function() {
        var t = this, a = this.data.Difference;
        console.log(a), this.data.setTime = setInterval(function() {
            if (console.log("循环中"), (a -= 1e3) <= 0) return clearInterval(t.data.setTime), void t.setData({
                statusa: 0
            });
            t.transformRemainTime(a), console.log(t.data.countdown, "这是时分秒");
        }, 1e3);
    },
    transformRemainTime: function(t) {
        var a = Math.floor(t / 1e3);
        console.log(a), console.log(Math.floor(a / 3600 / 24));
        var e = this.formatTime(Math.floor(a / 3600 / 24));
        console.log(e);
        var i = this.formatTime(Math.floor(a / 3600 % 24)), o = this.formatTime(Math.floor(a / 60 % 60)), s = this.formatTime(Math.floor(a % 60));
        "00" == e ? this.setData({
            countdown: "".concat(i, ":").concat(o, ":").concat(s)
        }) : this.setData({
            countdown: "".concat(e, ":").concat(i, ":").concat(o, ":").concat(s)
        });
    },
    formatTime: function(t) {
        return console.log(t), t < 10 ? "0" + t : t;
    },
    getHb: function(a) {
        if (!this.data.link.is_advert || this.data.link.is_browse) if (this.data.tapOne) console.log("正在领取"); else {
            this.setData({
                tapOne: !0
            });
            var e = this;
            e.getData(a);
            var i = t.getNetAddresss("plugin.red-packet.api.red-packet-logs.memberAmount");
            t._getNetWork({
                url: i,
                data: {
                    red_packet_id: a,
                    uid: wx.getStorageSync("yz_uid")
                },
                success: function(t) {
                    var a = t.data;
                    console.log(a.data), e.setData({
                        linMoney: Number(a.data).toFixed(2),
                        backsta: !0
                    }), setTimeout(function() {
                        e.setData({
                            tapOne: !1
                        });
                    }, 1e3), 0 == a.result ? (e.setData({
                        showCart: !1
                    }), wx.showToast({
                        title: a.msg,
                        icon: "none"
                    })) : a.data.price ? "0" == a.data.price && (e.setData({
                        showCart: !1
                    }), wx.showToast({
                        title: a.msg,
                        icon: "none"
                    })) : e.setData({
                        showCart: !0
                    });
                },
                fail: function(t) {
                    setTimeout(function() {
                        e.setData({
                            tapOne: !1
                        });
                    }, 1e3), console.log(t);
                }
            });
        } else wx.showModal({
            title: "请先点击顶部图片进行浏览!",
            icon: "none",
            duration: 1500,
            showCancel: !1
        });
    },
    getShare: function() {
        var a = this, e = t.getNetAddresss("plugin.red-packet.api.red-packet-logs.share");
        t._getNetWork({
            url: e,
            success: function(t) {
                var e = t.data;
                console.log(e), a.setData({
                    share_title: e.data.share_title,
                    share_content: e.data.share_content,
                    share_pictures: e.data.share_pictures
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    goqg: function(t) {
        console.log(t);
        var a = t.currentTarget.dataset.id;
        wx.navigateTo({
            url: "/packageA/detail_v2/detail_v2?id=" + a
        });
    }
});